package com.lan.app.utils;

import org.springframework.web.multipart.MultipartFile;

import java.io.*;

public class FileUtils {

    public static void upload(MultipartFile multipartFile, String path) throws Exception {
        File f = new File(path);
        File fileDir = f.getParentFile();
        if (!fileDir.exists()) {
            fileDir.mkdirs();
        }
        multipartFile.transferTo(f);
    }

    public static void upload(ByteArrayOutputStream out, String path) {
        FileOutputStream fileOutputStream = null;
        try {
            File f = new File(path);
            File fileDir = f.getParentFile();
            if (!fileDir.exists()) {
                fileDir.mkdirs();
            }
            fileOutputStream = new FileOutputStream(path);
            fileOutputStream.write(out.toByteArray());
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


}
